Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --stub-watch option #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

shumbo
Copy link

@shumbo shumbo commented May 26, 2021

Overview

First of all, thank you for maintaining such a great project!

This PR adds --stub-watch option to gripmock. With this option enabled, the program will watch for changes in the stub directory, and when you make changes in the directory, it will 1) clear all registered stubs (just as calling /clear) and 2) register stubs in the directory.

Motivation

I store all stubs in the directory and load them via --stub option. While this works okay, I need to restart the program every time I edit the stub files, and I thought it would be nice if the program can detect changes and automatically use the latest version.

This is especially useful when we're debugging clients using gripmock as a server.

Discussion

  • I decided to clear stubs on change because there is no trivial way to replace a specific stub. This might be problematic if you use both --stub-watch and POST /add at the same time, as stubs added by HTTP API will be deleted.
    • I think you usually want to use one, not both.
    • We might add a field in stub indicating which file it came from to solve this problem.
  • I'm not sure if there's a need for this feature. I'm hoping this to be a PoC for people who are using gripmock in a similar way to me even if it doesn't get merged to the mainstream.
  • I'm new to Golang. My apologies if there is any rudimentary error.

@jekiapp
Copy link
Contributor

jekiapp commented Jul 28, 2021

Hi, sorry for the late reply

I think this is one neat PR. I really like the idea, I also agree with you that people will normally use one method for stub strategy (either via API or via file).

One thing that missing from this PR is the test. Either you create unit test to cover the watch-stub or you can create one example to prove this method is working. Until then I cannot merge the PR, it's company policy 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants